<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * 点评 model
 *
 */
class Commentmodel extends CI_Model {

	function __construct()
    {
        parent::__construct();
    }
    
    /**
     * 添加评论
     *
     * @param unknown_type $data
     * @return unknown
     */
    function insert_comment($data=array())
    {
    	if(empty($data) || !isset($data['comment_id']) || empty($data['comment_id']) ||
    						!isset($data['uid']) || empty($data['uid']) || 
    						!isset($data['content']) || empty($data['content'])){

    		return false;
    	}
    	
    	$this->db->set('id', '(SELECT UUID())', FALSE);
    	return $this->db->insert('comments', $data);
    }
    
    /**
     * 获取对应用或专辑的评论(关联用户)
     *
     * @param unknown_type $comment_id
     * @param unknown_type $comment_type
     */
    function get_comments_by_type($comment_id='', $comment_type=1, $uid='')
    {
    	$result = array();
    	//设置分页
    	$this->dblib->set_query_limit();
    	//查询
    	$this->db->select('c.id, c.content, c.createtime, u.id as user_id, u.name as user_name, u.photo as user_photo')
    			 ->from('comments as c')
    			 ->join('user as u', 'c.uid=u.id')
    			 ->where(array('c.comment_id' 		=> $comment_id, 
					   			'c.comment_type'	=> $comment_type,
					   			//'c.uid'				=> $uid,
					   			'c.share_or_comment' => IS_COMMENT))
				->order_by('c.createtime', 'desc');
    	$query = $this->db->get();
    	if($query->num_rows() > 0){
    		$result = $query->result_array();
    		$this->load->library('uploadimglib');
			//设置photo路径
			foreach ($result as $k=>$v){
				$result[$k]['user_photo'] = $this->uploadimglib->re_image_path($v['user_photo']);
			}
    	}
    	return $result;
    }
}

/* End of file commentmodel.php */
/* Location: ./application/models/commentmodel.php */